
/**
 * @author Johannes Riedmann
 * @author Lukas K�ll
 * @author David Medenjak
 */
public class Test {

    private static String hr = "----------------------------------------" +
    		"--------------------------------------";
    /**
     * @param args
     */
    public static void main(String[] args) {
        print("Welcome to exercise 6 Test suite!");
        testFactoryWorks();
        
        testStatisticsWork();
        testMap();
    }
    
    private static void testFactoryWorks(){
        print(hr);
        print("Testing if adding robots to factory works");
        Fabrik fac = new Fabrik("myFactory");
        Roboter r1 = fac.createRoboter("SchwenkarmSchweissRoboter");
        print("created schwenkarm-schweiss-robot with id " + r1.getId());
        fac.addRoboter(r1);
        Roboter r2 = fac.createRoboter("RaupenSchweissRoboter");
        print("created raupen-schweiss-robot with id " + r2.getId());
        fac.addRoboter(r2);
        print("state of the factory now: ");
        System.out.println(fac.toString());
        print(hr);
        print("changing robots operation mode to LackierRoboter using ID " + r1.getId());
        fac.changeRoboterOperationMode(r1.getId(), "LackierRoboter");
        print("robot with ID "+r1.getId()+" operation mode is " + r1.getOperationModeName());
        print(hr);
        print("removing robot with id "+r2.getId()+" from the factory");
        fac.removeRoboter(r2.getId());
        print("state of the factory now:");
        System.out.println(fac.toString());
    }
    
    private static void testStatisticsWork(){
        
        print(hr);
        print("");
        print("Here are the statistics tests");
        print("");
        print(hr);
        
        print("Creating 3 Factories, this is what the collection looks like:");
        Fabrik fac1 = new Fabrik("Erste Fabrik");
        Fabrik fac2 = new Fabrik("Zweite Fabrik");
        Fabrik fac3 = new Fabrik("Dritte Fabrik");
        
        Map fabrikmap = new Map();
        fabrikmap.add("fac1", fac1);
        fabrikmap.add("fac2", fac2);
        fabrikmap.add("fac3", fac3);
        
        Iter it = fabrikmap.iterator();
        while(it.hasNext()){
            Fabrik fab = (Fabrik) it.next();
            print(fab.getName());
        }
        print(hr);
        print("Adding each 3 SchwenkarmSchweissRoboter with rotation and temperature " +
        		"values from 1-9 to every factory");
        int val = 1;
        for(int i = 1; i <= 3; i++){
            Fabrik f = (Fabrik)fabrikmap.get("fac"+i);
            for(int j = 0; j < 3; j++){
                SchwenkarmRoboter r = (SchwenkarmRoboter)f.createRoboter("SchwenkarmSchweissRoboter");
                r.increaseRotationen(val);
                r.increaseOperatingHours(val*3);
                SchweissRoboter s = (SchweissRoboter) r.getOperationMode();
                s.setWorkingTemperature(val);
                f.addRoboter(r);
                val++;
            }
        }
        print(hr);
        print("Adding each 3 RaupenLackierRoboter with way and capacity" +
                "values from 1-9 to every factory");
        val = 1;
        for(int i = 1; i <= 3; i++){
            Fabrik f = (Fabrik)fabrikmap.get("fac"+i);
            for(int j = 0; j < 3; j++){
                RaupenRoboter r = (RaupenRoboter)f.createRoboter("RaupenLackierRoboter");
                r.increaseWegstrecke(val);
                r.increaseOperatingHours(val*2);
                LackierRoboter s = (LackierRoboter) r.getOperationMode();
                s.setCapacity(val);
                f.addRoboter(r);
                val++;
            }
        }
        
        print(hr);
        print("Adding each 3 SchwenkarmLackierRoboter with rotations and capacity" +
                "values from 1-9 to every factory");
        val = 1;
        for(int i = 1; i <= 3; i++){
            Fabrik f = (Fabrik)fabrikmap.get("fac"+i);
            for(int j = 0; j < 3; j++){
                SchwenkarmRoboter r = (SchwenkarmRoboter)f.createRoboter("SchwenkarmLackierRoboter");
                r.increaseRotationen(val);
                r.increaseOperatingHours(val*2);
                LackierRoboter s = (LackierRoboter) r.getOperationMode();
                s.setCapacity(val);
                f.addRoboter(r);
                val++;
            }
        }
        
        print(hr);
        print("Adding each 3 RaupenSchweissRoboter with way and capacity" +
                "values from 1-9 to every factory");
        val = 1;
        for(int i = 1; i <= 3; i++){
            Fabrik f = (Fabrik)fabrikmap.get("fac"+i);
            for(int j = 0; j < 3; j++){
                RaupenRoboter r = (RaupenRoboter)f.createRoboter("RaupenSchweissRoboter");
                r.increaseWegstrecke(val);
                r.increaseOperatingHours(val*3);
                SchweissRoboter s = (SchweissRoboter) r.getOperationMode();
                s.setWorkingTemperature(val);
                f.addRoboter(r);
                val++;
            }
        }
        
        print(hr);
        print("Average rotations for all factories should be (45)/9 = 5");
        it = fabrikmap.iterator();
        int rotationSum = 0;
        float waySum = 0;
        while(it.hasNext()){
            Fabrik fab = (Fabrik) it.next();
            rotationSum += fab.getAverageRotations();
            waySum += fab.getAverageWay();
        }
        double averageRotations = rotationSum / 3.0;
        double averageWay = rotationSum / 3.0;
        print("Result: "+averageRotations);
        
        print(hr);
        print("Average way for all factories should be (45)/9 = 5");
        print("Result: "+averageWay);
        
        print(hr);
        print("");
        print("Statistics Tests for a single factory");
        print("we do test fac1 here");
        print(hr);
        
        print("Average operation hours for all robots (should be 5) :" + fac1.getAverageOperatingHours());
        print("Average operation hours for LackierRoboter's (should be 4):" + fac1.getAverageOperatingHoursForOperationMode("LackierRoboter"));
        print("Average operation hours for SchweissRoboter's (should be 6):" + fac1.getAverageOperatingHoursForOperationMode("SchweissRoboter"));
        print("Average operation hours for SchwenkarmRoboter's (should be 5):" + fac1.getAverageOperatingHoursForRobotertype("SchwenkarmRoboter"));
        print("Average operation hours for RaupenRoboter's (should be 5):" + fac1.getAverageOperatingHoursForRobotertype("RaupenRoboter"));
        print("");
        print("Average rotations for all SchwenkarmRoboter's (should be 5):" + fac1.getAverageRotations());
        print("Average rotations for LackierRoboter's (should be 2):" + fac1.getAverageRotationsForOperationMode("LackierRoboter"));
        print("Average rotations for SchweissRoboter's (should be 2):" + fac1.getAverageRotationsForOperationMode("SchweissRoboter"));
        print("");
        print("Average way for all RaupenRoboter's (should be 2):" + fac1.getAverageWay());
        print("Average way for LackierRoboter's (should be 2):" + fac1.getAverageWayForOperationMode("LackierRoboter"));
        print("Average way for SchweissRoboter's (should be 2):" + fac1.getAverageWayForOperationMode("SchweissRoboter"));
        print("");
        print("Minimum temperature for all SchweissRoboter's (should be 1): " + fac1.getMinimumWorkingTemperature());
        print("Minimum temperature for RaupenRoboter's (should be 1): " + fac1.getMinimumWorkingTemperatureForRobotertyp("RaupenRoboter"));
        print("Minimum temperature for SchwenkarmRoboter's (should be 1): " + fac1.getMinimumWorkingTemperatureForRobotertyp("SchwenkarmRoboter"));
        print("");
        print("Maximum temperature for all SchweissRoboter's (should be 3): " + fac1.getMaximumWorkingTemperature());
        print("Maximum temperature for RaupenRoboter's (should be 3): " + fac1.getMaximumWorkingTemperatureForRobotertyp("RaupenRoboter"));
        print("Maximum temperature for SchwenkarmRoboter's (should be 3): " + fac1.getMaximumWorkingTemperatureForRobotertyp("SchwenkarmRoboter"));
    }   
    
    private static void testMap(){
        print(hr);
        print("Testing the Map class");
        print("Creating a Map with strings as keys and values:");
        Map map = new Map();
        map.add("test1", "wert von test1");
        map.add("test2", "wert von test2");
        Iter it = map.iterator();
        while(it.hasNext()){
            print(it.next().toString());
        }
        print("Retrieving value of test2 (should be 'wert von test2'):");
        print(map.get("test2").toString());
    }
    
    private static void print(String string){
        System.out.println("> " + string);
    }
}
